<template>
	<view class="baseForm">
		<u-loading-page :loading="loading"></u-loading-page>
		<view v-if="!loading" class="overhidden">
			<view v-if="props.id" class="" style="width: 100%; background-color: rgba(22, 37, 78, 0.85); height: 110px">
				<view class="" style="padding: 22px 15px; display: flex; justify-content: space-between">
					<view class="" style="display: flex; flex-direction: column">
						<text style="font-size: 18px; color: #fff; font-weight: bold">
							{{ useDictionaryStore().filterDictName('EamRepairStatus', taskInfo.repairStatus) }}
						</text>
						<text style="font-size: 15px; color: #fff; margin-top: 9px">报修编号：{{ taskInfo.repairCode }}</text>
					</view>
					<image v-show="taskInfo.repairTeamName" src="@/static/image/order.png" style="width: 50px; height: 50px" />
				</view>
			</view>

			<view :class="props.id ? 'mt-10-' : ''">
				<!-- 选择设备 -->
				<view v-if="props.isRead != 1" class="searchScan">
					<u-input placeholder="请选择设备或扫描设备码" disabled>
						<template #suffix>
							<u-icon name="scan" size="27px" :bold="false" @click="scanHandle"></u-icon>
						</template>
					</u-input>
					<u-button class="addBtn1" size="small" type="primary" text="选择" @click="jump('/eam/equ/selectDevice/index')"></u-button>
				</view>

				<u--form labelPosition="top" :model="taskInfo" :rules="rules" labelWidth="300" ref="uForm" class="form" errorType="toast">
					<!-- 设备详情 -->
					<DeviceInfoTemplate :taskInfo="taskInfo"></DeviceInfoTemplate>
					<!-- 故障信息 -->
					<RepairOrderInfo v-if="props.isRead == 1" :taskInfo="taskInfo"></RepairOrderInfo>
					<!-- 故障编辑信息 -->
					<view v-else class="plan card record-content">
						<view class="title">故障信息</view>
						<u-form-item label="故障时间" prop="timeOfFailure" required>
							<!-- <u-radio-group v-model="taskInfo.faultStatus">
								<u-radio
									:customStyle="{
										marginRight: '30px',
										fontSize: '14px'
									}"
									shape="square"
									v-for="(item, index) in useDictionaryStore().filterDictList('EamFaultStatus')"
									:key="index"
									:label="item.label"
									:name="item.value"
								></u-radio>
							</u-radio-group> -->
							
							<view
								@click="openTimeSelect"
								class="flex input-box">
								<u--input
									v-model="
										taskInfo.timeOfFailure
									"
									border="none"
									disabled
									disabledColor="#ffffff"
									placeholder="请选择故障时间"></u--input>
								<image
									@click.stop="
										clearInfo([
											'timeOfFailure',
											'timeOfFailureCode',
										])
									"
									v-show="
										taskInfo.timeOfFailure
									"
									src="@/static/image/delete.png" />
								<image
									v-show="
										!taskInfo.timeOfFailure
									"
									src="@/static/image/calendar.png"
									style="
										width: 16px;
										height: 16px;
										margin-top: 2px;
									" />
							</view>
							
						</u-form-item>
						<u-form-item label="故障状态" prop="faultStatus" required>
							<u-radio-group v-model="taskInfo.faultStatus">
								<u-radio
									:customStyle="{
										marginRight: '30px',
										fontSize: '14px'
									}"
									shape="square"
									v-for="(item, index) in useDictionaryStore().filterDictList('EamFaultStatus')"
									:key="index"
									:label="item.label"
									:name="item.value"
								></u-radio>
							</u-radio-group>
						</u-form-item>
						<u-form-item label="故障等级" prop="repairLevel" required>
							<u-radio-group v-model="taskInfo.repairLevel">
								<u-radio
									:customStyle="{ marginRight: '30px' }"
									shape="square"
									v-for="(item, index) in useDictionaryStore().filterDictList('EamFaultLevel')"
									:key="index"
									:label="item.label"
									:name="item.value"
								></u-radio>
							</u-radio-group>
						</u-form-item>
						<u-form-item label="故障描述" prop="remarks" required>
							<u--textarea
								v-model="taskInfo.remarks"
								placeholder="请输入故障描述"
								height="45px"
								:customStyle="{
									marginTop: '2px'
								}"
							></u--textarea>
						</u-form-item>
						<u-form-item label="故障图片">
							<upload-image
								:multiple="false"
								:accept="accept"
								@fileChange="getSceneImages"
								camera="back"
								:list="taskInfo.images"
								:capture="capture"
								style="margin-top: 4px"
								folderName="eam/equ/eamRepairOrders"
							></upload-image>
						</u-form-item>
						<view v-if="props.id" class="detail" style="margin-top: -9px">
							<view class="flex justify-between m-7-0 c-a8b2bb">
								<text>报修时间</text>
								<text>{{ taskInfo?.repairTime || '' }}</text>
							</view>
							<view class="flex justify-between m-7-0 c-a8b2bb">
								<text>报修人</text>
								<text>
									{{ taskInfo?.repairUserName || '' }}
								</text>
							</view>
						</view>
					</view>

					<!-- 维修信息 -->
					<RepairHandleInfo v-if="props.isRead == 1" :taskInfo="taskInfo"></RepairHandleInfo>

					<!-- 维修编辑信息 -->
					<view v-else class="plan card record-content">
						<view class="title flex justify-between">
							<text>维修信息</text>
						</view>
						<view class="question">
							<view>
								<u-form-item label="维修班组">
									<view @click="hideKeyboard" class="flex input-box">
										<u--input v-model="taskInfo.repairTeamName" border="none" placeholder="请选择维修班组" readonly class="input-self"></u--input>
										<image @click.stop="changeCrew({})" v-show="taskInfo.repairTeamName" src="@/static/image/delete.png" />
									</view>
								</u-form-item>
								<u-form-item label="维修人">
									<view @click="crewhideKeyboard" class="flex input-box">
										<u--input v-model="taskInfo.repairTeamUserName" border="none" placeholder="请选择维修人" readonly class="input-self"></u--input>
										<image @click.stop="changeMember({})" v-show="taskInfo.repairTeamUserName" src="@/static/image/delete.png" />
									</view>
								</u-form-item>
							</view>
						</view>
					</view>

					<!-- 操作历史 -->
					<OperateHistory
						v-if="props.isRead == 1 && operationRecordList && operationRecordList.length"
						:taskInfo="operationRecordList"
						:key="operationKey"
						@sort="showOperationRecord">
					</OperateHistory>

					<view v-if="!props.isRead" style="padding: 0 10px">
						<!-- 新建按钮 -->
						<button v-show="!props.id" type="primary" @click="submit" :disabled="postLoading" :loading="postLoading" class="submit_btn">立即报修</button>
						<!-- 未应答状态下，可以取消和修改 -->
						<view v-show="props.id && taskInfo.repairStatus == 0" class="flex">
							<button class="submit_btn grey_btn flex-1" @click="openPrompt(taskInfo, 5)">取消</button>
							<button type="primary" class="submit_btn flex-1" :disabled="postLoading" :loading="postLoading" @click="submit">修改</button>
						</view>
					</view>
					<!-- 已应答和维修中的情况，可以进行故障关闭操作，输入关闭原因 -->
					<view v-if="props.id" style="padding: 0 10px" class="flex">
						<!-- 待确认状态下，可以进行确认和返修操作 -->
						<button v-if="taskInfo.repairStatus == 3" class="submit_btn orange-btn orange-shadow flex-1" @click="openPrompt(taskInfo, 2)">返修</button>
						<button type="primary" v-if="taskInfo.repairStatus == 3" class="submit_btn flex-1" @click="openPrompt(taskInfo, 4)">确认</button>
						<!-- 已应答和维修中的情况，可以进行故障关闭操作，输入关闭原因 ，后改为维修中的不能故障关闭-->
						<button v-if="taskInfo.repairStatus == 1" class="submit_btn grey_btn flex-1" @click="openPrompt(taskInfo, 6)">
							故障关闭
						</button>
						
						<!-- 待确认状态下，可以进行确认和返修操作 -->
						<!-- && taskInfo.repairUser != useUserStore().userInfo.userId -->
						<button
							v-if="props.isRead && taskInfo.repairStatus == '0'"
							type="primary"
							class="submit_btn flex-1"
							@click="openPrompt(taskInfo, 1)">
							应 答
						</button>
					</view>
				</u--form>
			</view>
		</view>
		<!-- 班组选择 picker -->
		<u-picker :show="showCrewPicker" :columns="crewList" keyName="teamName" immediateChange @cancel="showCrewPicker = false" @confirm="changeCrew"></u-picker>
		<!-- 人员选择 picker -->
		<u-picker :show="showMemberPicker" :columns="memberList" keyName="memberName" immediateChange @cancel="showMemberPicker = false" @confirm="changeMember"></u-picker>
		<u-modal :show="showImport" ref="uModal" :content="promptText" confirmText="确认" showCancelButton @cancel="cancelImport" @confirm="confirmImport">
			<view class="slot-content">
				<text v-show="promptStatus !== 6 && promptStatus !== 2">{{ promptText }}</text>
				<view v-show="promptStatus === 6 || promptStatus === 2" class="">
					<!-- <text>{{promptText}}</text> -->
					<u-input v-model="promptReason" :placeholder="promptText" style="width: 500rpx"></u-input>
				</view>
			</view>
		</u-modal>
		
		<!-- 时间选择picker弹窗 -->
		<u-datetime-picker
			v-model="taskInfo.timeOfFailureCode"
			:show="showTime"
			mode="datetime"
			@cancel="showTime = false"
			@confirm="timeSelect"></u-datetime-picker>
			
	</view>
</template>

<script lang="ts" setup>
import { nextTick, ref, toRaw, toRefs, watch, reactive, computed } from 'vue';
import { onShow, onPullDownRefresh, onLaunch, onBackPress } from '@dcloudio/uni-app';
import UploadImage from '@/components/upload-image-ssr.vue';
import DeviceInfoTemplate from '@/pages/eam/equ/repairOrderCreate/components/deviceInfo.vue';
import RepairOrderInfo from '@/pages/eam/equ/repairOrderCreate/components/repairOrderInfo.vue';
import RepairHandleInfo from '@/pages/eam/equ/repairOrderCreate/components/repairHandleInfo.vue';
import OperateHistory from '@/pages/eam/equ/repairOrderCreate/components/operateHistory.vue';
import { http } from '@/utils/http';
import { getSecondTime, getTimes } from '@/utils/common';
import { useUserStore } from '@/stores/useUserStore';
import { getCrewMemberListApi, getCrewListApi } from '@/api/jt-api';
import { useEamStore } from '@/stores/useEamStore';
import { useDictionaryStore } from '@/stores/useDictionaryStore';
import { toScanCode } from '@/components/hs-scancode/scan.js';
import dayjs from 'dayjs';

const props = defineProps({
	id: {
		type: String,
		default: ''
	},
	isRead: {
		type: String,
		default: '' // 1是查看
	},
	assetId: {
		// 设备Id
		type: String,
		default: ''
	},
	assetKind: {
		type: String,
		default: '1'
	},
	// 报修来源 按照字典表来 EamFaultSource
	repairSource: {
		type: String,
		default: '1'
	}
});

// 获取当前页面实例
const pages = getCurrentPages();
// 获取当前页面的实例
const currentPage = pages[pages.length - 1];
// 获取页面路径
const pagePath = currentPage.$page.fullPath;

const options = currentPage.options; // 当前页面的查询参数对象

// 表单规则定义
const rules = ref({
	assetName: {
		type: 'string',
		required: true,
		message: '请选择设备',
		trigger: ['change']
	},
	faultStatus: {
		type: 'string',
		required: true,
		message: '请选择故障状态',
		trigger: ['change']
	},
	repairLevel: {
		type: 'string',
		required: true,
		message: '请选择故障等级',
		trigger: ['change']
	},
	timeOfFailure: {
		type: 'string',
		required: true,
		message: '请选择故障时间',
		trigger: ['change']
	},
	remarks: [
		{
			type: 'string',
			required: true,
			message: '请填写故障描述',
			trigger: ['blur']
		},
		{
			type: 'string',
			required: true,
			min: 1,
			max: 255,
			message: '故障描述不能超过 255 个字符',
			trigger: ['blur']
		}
	]
});

//班组
let crewList = ref<any>([]);
//人员
let memberList = ref<any>([]);

// 确认班组信息
const changeCrew = async (e) => {
	if (e?.value?.length) {
		taskInfo.repairTeamCode = e.value[0].teamCode;
		taskInfo.repairTeamName = e.value[0].teamName;
		taskInfo.repairTeamId = e.value[0].id;
		taskInfo.repairTeamText = e.value[0].repairTeamText;
		getMembers(taskInfo.repairTeamId);
		clearRepairTeamUser();
	} else {
		clearRepairTeam();
		clearRepairTeamUser();
		memberList.value[0] = [];
	}
	showCrewPicker.value = false;
};

// 确认班组人员变化
const changeMember = (e: any) => {
	if (e?.value?.length) {
		taskInfo.repairTeamUserEmpNo = e.value[0].memberEmpNo;
		taskInfo.repairTeamUserName = e.value[0].memberName;
		taskInfo.repairTeamUserText = e.value[0].repairTeamUserText;
	} else {
		taskInfo.repairTeamUserEmpNo = '';
		taskInfo.repairTeamUserName = '';
		taskInfo.repairTeamUserText = '';
	}
	showMemberPicker.value = false;
};

// 清空联动维修人员信息
function clearRepairTeamUser() {
	taskInfo.repairTeamUserEmpNo = '';
	taskInfo.repairTeamUserName = '';
	taskInfo.repairTeamUserText = '';
}

// 清空联动维修班组信息
function clearRepairTeam() {
	taskInfo.repairTeamCode = '';
	taskInfo.repairTeamName = '';
	taskInfo.repairTeamId = '';
	taskInfo.repairTeamText = '';
}

// 获取班组列表
async function getCrews() {
	let list: any = (await getCrewListApi({ teamType: '1' })) || [];
	list.forEach((item) => {
		item.repairTeamText = `${item.teamCode}-${item.teamName}`;
	});
	crewList.value[0] = list;
}

// 获取人员列表
async function getMembers(id) {
	let list: any = (await getCrewMemberListApi({ id: id })) || [];
	list.forEach((item) => {
		item.repairTeamUserText = `${item.memberEmpNo}-${item.memberName}`;
	});
	memberList.value[0] = list;
}

getCrews();
/**
 * 选择工作中心
 */
const showCrewPicker = ref(false);

/**
 * 选择班组
 */
const showMemberPicker = ref(false);

/**
 * 组织键盘弹出
 */
function hideKeyboard() {
	showCrewPicker.value = true;
	uni.hideKeyboard();
}
/**
 * 组织键盘弹出
 */
function crewhideKeyboard() {
	showMemberPicker.value = true;
	uni.hideKeyboard();
}

// 选择设备信息
const deviceList = computed(() => JSON.parse(useEamStore().deviceList));

// 网页跳转
function jump(item, id = '') {
	uni.navigateTo({
		url: id ? `/pages${item}?id=${id}` : `/pages${item}`,
		fail: () => {
			uni.showToast({
				title: '敬请期待',
				icon: 'error'
			});
		}
	});
}

// 跳转至备件页面
function jumpUrl(url) {
	uni.navigateTo({
		url: url,
		fail: () => {
			uni.showToast({
				title: '敬请期待',
				icon: 'error'
			});
		}
	});
}

// 点击扫码
const searchText = ref('');
// function openScan() {
// 	/* #ifdef H5 */
// 	uni.showToast({
// 		icon: "none",
// 		title: "请到安卓设备进行扫码",
// 	});
// 	/* #endif */
// 	// 只允许通过相机扫码
// 	uni.scanCode({
// 		scanType: ["barCode", "qrCode"],
// 		onlyFromCamera: true,
// 		success: function (res) {
// 			searchText.value = JSON.parse(JSON.stringify(res.result));
// 			getDeviceInfo(searchText.value);
// 			console.log("条码类型：" + res.scanType);
// 			console.log("条码内容：" + res.result);
// 		},
// 	});
// }

function scanHandle() {
	toScanCode({
		onlyFromCamera: true // 只允许通过相机扫码
	})
		.then((res) => {
			uni.showToast({
				icon: 'none',
				title: res
			});
			searchText.value = res;
			getDeviceInfo(searchText.value);
		})
		.catch((e) => {
			uni.showToast({
				icon: 'error',
				title: e
			});
		});
}

// 是否折叠
const isCollapse = ref(false);

// 初始化页面，获取检查详情
let taskInfo = reactive({
	id: '',
	// 设备信息
	assetId: '',
	assetName: '',
	assetCode: '',
	assetTypeName: '',
	assetModelNo: '',
	assetBrandName: '',
	usingDepartmentName: '',
	usingPersonName: '',
	locationName: '',
	// 故障信息
	images: [],
	executeFiles: [],
	faultStatus: '1',
	repairLevel: '1',
	remarks: '',
	memo: '',
	timeOfFailure:'',
	timeOfFailureCode: null,

	// 维修信息
	repairTeamId: '',
	repairTeamCode: '',
	repairTeamName: '',
	repairTeamText: '',

	repairTeamUser: '',
	repairTeamUserText: '',
	repairTeamUserName: '',
	repairTeamUserEmpNo: '',

	// 以下为原生数据
	version: '',
	// assetTypeId: "",
	repairTime: '',
	repairUser: useUserStore().userInfo.userId,
	repairUserName: useUserStore().userInfo.userName,
	repairCode: '',
	// faultStatus: "",
	// repairLevel: "",
	// repairTeamId: "",
	// repairTeamUser: "",
	answerTime: '',
	repairStartTime: '',
	repairEndTime: '',
	faultMode: '',
	faultPhenomenon: '',
	faultReason: '',
	faultPosition: '',
	faultHandleMeasure: '',
	parts: [],
	repairSituation: '',
	repairStatus: '',
	outSourcing: '',
	createTime: '',
	createdUserId: '',
	createdUserName: '',
	lastUpdateTime: '',
	lastUpdatedUserId: '',
	lastUpdatedUserName: '',
	enabled: '',
	deleted: '',
	assetKind: props.assetKind || '1',
	repairSource: props.repairSource || '1'
});
const loading = ref(false);

// 开始时间选择
const showTime = ref(false);
function timeSelect(e) {
	console.log('e.value', e.value)
	taskInfo.timeOfFailureCode = e.value;
	taskInfo.timeOfFailure = getTimes(e.value);
	showTime.value = false;
}
function openTimeSelect() {
	if (!taskInfo.timeOfFailureCode) {
		taskInfo.timeOfFailureCode = Number(new Date());
	}
	showTime.value = true;
	uni.hideKeyboard();
}

// 摄像头参数设置
const capture = ref(["camera",'album']);
const accept = ref('image');

// 获取现场图片
function getSceneImages(list) {
	taskInfo.images = list;
}

// 清空数据
function clearInfo(arr) {
	arr?.map((item) => {
		taskInfo[item] = "";
	});
}

// 校验提交
const uForm = ref();
const postLoading = ref(false);
function submit() {
	if (!taskInfo.assetId) {
		uni.showToast({
			title: '请选择报修设备',
			icon: 'none'
		});
		return false;
	}
	uForm.value.validate().then(async () => {
		postLoading.value = true;
		const result: any = await http({
			method: 'POST',
			url: `/eam/eamrepairorder/save`,
			data: taskInfo
		}).finally(() => {
			postLoading.value = false;
		});

		uni.showToast({
			title: '提交成功'
		});

		uni.navigateTo({
			url: `/pages/eam/equ/repairOrder/index`
		});
	});
}

async function initPage() {
	try {
		loading.value = true;
		const result: any = await http({
			method: 'GET',
			url: `/eam/eamrepairorder/get/${props.id}`,
			data: {
				assetKind: props.assetKind
			}
		}).finally(() => {
			uni.stopPullDownRefresh();
		});
		taskInfo = Object.assign(taskInfo, {
			...result.data,
			images: result.data.images || [],
			executeFiles: result.data.executeFiles || [],
			parts: result.data.parts || []
		});

		if (taskInfo.repairTeamUserEmpNo) {
			getMembers(taskInfo.repairTeamId);
			taskInfo.repairTeamUserText = taskInfo.repairTeamUserEmpNo + '-' + taskInfo.repairTeamUserName;
		}
		if (taskInfo.repairTeamCode) {
			taskInfo.repairTeamText = taskInfo.repairTeamCode + '-' + taskInfo.repairTeamName;
			getMembers(taskInfo.repairTeamId);
		}
		getHistoryList();
		loading.value = false;
	} catch (e) {
		console.log(e);
	}
}

// 页面刷新
function refresh() {
	props.id && initPage();
	if (!props.id) {
		taskInfo.timeOfFailure=dayjs().format('YYYY-MM-DD HH:mm:ss')
		taskInfo.timeOfFailureCode= Number(new Date())
	}
}

// 下拉加载
onPullDownRefresh(() => {
	uni.showToast({
		title: 'onPullDownRefresh'
	});
	refresh();
});

// 页面显示回调
refresh();

// 过滤设备信息
function filterDeviceInfo(data) {
	taskInfo.assetId = data.id;
	taskInfo.assetCode = data.assetCode;
	taskInfo.assetName = data.assetName;
	taskInfo.locationName = data.locationName;
	taskInfo.assetTypeName = data.assetTypeName;
	taskInfo.usingDepartmentName = data.usingDepartmentName;
	taskInfo.usingPersonName = data.usingPersonName;
	if (data.assetModelNo && data.assetBrandName) {
		taskInfo.assetModelNo = `${data.assetModelNo}-${data.assetBrandName}`;
	} else if (data.assetModelNo && !data.assetBrandName) {
		taskInfo.assetModelNo = `${data.assetModelNo}`;
	} else if (!data.assetModelNo && data.assetBrandName) {
		taskInfo.assetModelNo = `${data.assetBrandName}`;
	}
}

// 获取设备信息（接口请求）
async function getDeviceInfo(assetCode: string) {
	const { data }: any = await http({
		method: 'GET',
		url: `/eam/equAssetInfo/getInfo/${assetCode}`,
		data: {}
	});
	filterDeviceInfo(data);
}

// 监控设备选择id
watch(
	() => deviceList,
	async (newVal) => {
		if (newVal.value[0]?.id) {
			taskInfo.assetId = newVal.value[0]?.id;
			filterDeviceInfo(newVal.value[0]);
		}
		setTimeout(() => {
			useEamStore().setDeviceList();
		}, 1000);
	},
	{
		deep: true,
		immediate: true
	}
);

//首次进入，新建状态，清空设备报修缓存
// onShow(()=>{
// 	if (!props.id) {
// 		useEamStore().setDeviceList();
// 	}
// })

// 选择作业
const promptText = ref('');
const promptStatus = ref(null);
const promptReason = ref('');
function getStatusText(item, status) {
	promptReason.value = '';
	if (status === 5) {
		promptText.value = `请确认，是否取消编号为${item.repairCode}的报修单?`;
	} if (status === 1) {
		promptText.value = `请确认，是否应答编号为${item.repairCode}的报修单?`;
	}else if (status === 4) {
		promptText.value = `请确认，编号为${item.repairCode}的报修单是否维修完成?`;
	} else if (status === 2) {
		promptText.value = `请填写返修原因`;
	} else if (status === 6) {
		promptText.value = `请填写故障关闭原因`;
	}
}

const selectInfo = ref({});
const showImport = ref(false);
function openPrompt(row, status) {
	promptStatus.value = status;
	getStatusText(row, status);
	showImport.value = true;
	selectInfo.value = row;
}

// 取消选择
function cancelImport() {
	showImport.value = false;
	selectInfo.value = {};
}

function changeStatusReturn() {
	return new Promise(async (resolve, reject) => {
		const res = await http({
			method: 'POST',
			url: '/eam/equrepairorder/againRepair',
			data: {
				id: selectInfo.value.id,
				memo: promptReason.value
			}
		}).catch((e) => {
			// showImport.value = false;
		});
		resolve(res);
	});
}

function changeStatus() {
	return new Promise(async (resolve, reject) => {
		const res = await http({
			method: 'POST',
			url: '/eam/eamrepairorder/updateStatus',
			data: {
				id: selectInfo.value.id,
				repairStatus: promptStatus.value,
				memo: promptStatus.value === 6 ? promptReason.value : ''
			}
		}).catch((e) => {
			// showImport.value = false;
		});
		resolve(res);
	});
}
// 追加加工单
async function confirmImport() {
	if (promptStatus.value === 6 && !promptReason.value) {
		uni.showToast({
			title: '请填写故障关闭原因',
			icon: 'none'
		});
		return;
	}
	if (promptStatus.value === 2 && !promptReason.value) {
		uni.showToast({
			title: '请填写返修原因',
			icon: 'none'
		});
		return;
	}
	if (promptStatus.value === 2) {
		const { code } = await changeStatusReturn();
		if (code === 200) {
			uni.showToast({
				title: '操作成功'
			});
			let path = '';
			if (pagePath.includes('isRead=1')) {
				path = pagePath;
			} else if (pagePath.includes('isRead=')) {
				path = pagePath.replace('isRead=', 'isRead=1');
			} else {
				path = pagePath + '&isRead=1';
			}
			uni.navigateTo({
				url: path
			});
			// searchList()
		} else {
			uni.showToast({
				title: '操作失败'
			});
		}
	} else {
		const { code } = await changeStatus();
		if (code === 200) {
			uni.showToast({
				title: '操作成功'
			});
			if (promptStatus.value != 1) {
				let path = '';
				if (pagePath.includes('isRead=1')) {
					path = pagePath;
				} else if (pagePath.includes('isRead=')) {
					path = pagePath.replace('isRead=', 'isRead=1');
				} else {
					path = pagePath + '&isRead=1';
				}
				uni.navigateTo({
					url: path
				});
			} else {
				uni.navigateTo({
					url: `/pages/eam/equ/repairHandle/edit?assetKind=1&repairSource=1&id=${options.id}&isRead=1`
				});
			}
			
			// searchList()
		} else {
			uni.showToast({
				title: '操作失败'
			});
		}
	}

	showImport.value = false;
}

onBackPress(() => {
	back1();
	return true;
});
const back1 = () => {
	uni.navigateTo({
		url: '/pages/eam/equ/repairOrder/index',

		animationDuration: 200
	});
};

// 历史记录获取
const operationRecordList = ref<any>([]);
async function getHistoryList() {
	const res = await http({
		method: 'GET',
		url: `/eam/eamworkorderrecord/getByOrderId/${props.id}`,
		data: {}
	}).catch((e) => {});
	operationRecordList.value = res?.data || [];
}

const operationKey = ref(new Date());
// 排序
const showOperationRecord = () => {
	operationKey.value = new Date();
	if (operationRecordList.value.length > 0) {
		operationRecordList.value.reverse();
	}
};
</script>

<style lang="scss" scoped>
.handle-ok {
	min-width: 75px;
	color: #19be6b;
}
.card {
	background-color: #fff;
	margin: 10px 10px;
	border-radius: 8px;
	padding: 12px 12px;
	transition: all 300ms ease;
	box-shadow: 0 2px 6px rgba(3, 121, 255, 0.05);
}

.overhidden {
	overflow: hidden;
}

uni-page-body {
	height: 100%;
	background-color: #fbfbff;
}

.u-divider {
	margin: 10px 0;
}

.baseForm {
	background-color: #fbfbff;
	display: block;
}

.title {
	font-size: 16px;
	margin: 6px 0 14px;
	font-weight: bold;
	.u-icon {
		margin-right: 3px;
	}
}

.submit_btn {
	margin: 60rpx 20rpx;
	border-radius: 60rpx;
	height: 45px;
	font-size: 16px;
	line-height: 45px;
	box-shadow: 0 1px 10px rgba(3, 121, 255, 0.3);
}
.grey_btn {
	background-color: #fff !important;
	border: 1px solid #999;
	box-shadow: 0 1px 10px rgba(22, 37, 78, 0.08);
	color: #4f4f4f;
}

.searchScan {
	display: flex;
	height: 37px;
	padding: 12px 12px 0px;
	:deep(.u-input) {
		border: none;
		background-color: #fff !important;
		box-shadow: 0 1px 8px 0px rgb(19 10 236 / 8%);
	}
	.addBtn1 {
		width: 60px;
		height: 36px;
		margin-left: -3px !important;
		:deep(.u-button__text) {
			font-size: 14px !important;
		}
	}
}
:deep(.u-form-item__body) {
	padding: 4px 0 12px;
}
:deep(.u-form-item) {
	.u-form-item__body__left__content__label {
		color: #a8b2bb;
		font-size: 14px;
		margin-bottom: 1px;
	}
	.u-form-item__body__left__content__required {
		font-size: 16px;
	}
	// 单选不可编辑样式
	.u-radio {
		.u-radio__icon-wrap--disabled {
			background-color: rgb(255, 255, 255) !important;
		}
		.u-radio__icon-wrap--disabled--checked {
			background-color: rgb(41, 121, 255) !important;
			border-color: rgb(41, 121, 255) !important;
			.u-icon__icon {
				color: #fff !important;
			}
		}
		.u-radio__text {
			color: #16254e !important;
			font-size: 14px !important;
		}
	}

	.u-textarea--disabled {
		background-color: #fff !important;
	}
	.uni-textarea-textarea {
		color: #16254e !important;
	}

	.input-box {
		width: 100%;
		border: 0.5px solid #dadbde !important;
		border-radius: 4px;
		.u-input {
			pointer-events: none;
			height: 34px;
			padding-left: 10px !important;
		}
		image {
			padding: 7px 6px;
			width: 20px;
			height: 20px;
		}
	}
}

.mt-10- {
	margin-top: -30px;
}
</style>
